#ifndef _RATIONAL_
#define _RATIONAL_

struct Rational {
private:
    int numerator;
    int denominator;
    
    static int gcd (int, int);
    void rationalize();
    void normalize();
    
public:
    Rational(int i); 
    Rational(const Rational& r);
    Rational(int numerator, int denominator);
    
    Rational& operator = (const Rational& r);
    Rational  operator - () const; 
    Rational& operator += (const Rational& r); 
    Rational& operator -= (const Rational& r); 
    Rational& operator *= (const Rational& r); 
    Rational& operator /= (const Rational& r); 
    Rational& operator ++ ();
    Rational  operator ++ (int);
    Rational& operator -- ();
    Rational  operator -- (int);
    Rational  inv() const;    
    operator double () const;
    
    friend bool operator == (const Rational &, const Rational &);
    friend bool operator < (const Rational &, const Rational &);
};

Rational operator + (const Rational& a, const Rational& b);
Rational operator - (const Rational& a, const Rational& b);
Rational operator * (const Rational& a, const Rational& b);
Rational operator / (const Rational& a, const Rational& b);

bool operator == (const Rational& a, const Rational& b);
bool operator != (const Rational& a, const Rational& b);
bool operator <= (const Rational& a, const Rational& b);
bool operator >= (const Rational& a, const Rational& b);
bool operator <  (const Rational& a, const Rational& b);
bool operator >  (const Rational& a, const Rational& b);

#endif
